import org.junit.Before;
import org.junit.Test;

import java.io.PrintStream;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;

/**
 * Created with IntelliJ IDEA.
 * User: Thoughtworker
 * Date: 8/25/13
 * Time: 4:10 PM
 * To change this template use File | Settings | File Templates.
 */
public class GameTest {

    private ScoreApp scoreApp;
    private Game game;
    private Player player1;
    private Player player2;
    private PrintStream printStreamMock;

    @Before
    public void setUp() throws Exception {
        player1 = new Player(1);
        player2 = new Player(2);
        game = new Game(player1, player2);
        printStreamMock = mock(PrintStream.class);
        scoreApp = new ScoreApp(game, printStreamMock);
    }

    @Test
    public void shouldScorePlayerOneFirstTime() {
        game.scorePointPlayer(1);
        assertEquals("15/0", game.displayScore());
    }

    @Test
    public void shouldScorePlayerOneSecondTime() {
        game.scorePointPlayer(1);
        game.scorePointPlayer(1);
        assertEquals(game.displayScore(), "30/0");
    }

    @Test
    public void shouldScorePlayerTwoFirstTime() {
        game.scorePointPlayer(2);
        assertEquals(game.displayScore(), "0/15");
    }

    @Test
    public void shouldScorePlayerTwoSecondTime() {
        game.scorePointPlayer(2);
        game.scorePointPlayer(2);
        assertEquals(game.displayScore(), "0/30");
    }

    @Test
    public void shouldScorePlayerOneThirdTime() {
        game.scorePointPlayer(1);
        game.scorePointPlayer(1);
        game.scorePointPlayer(1);
        assertEquals(game.displayScore(), "40/0");
    }

    @Test
    public void shouldReturnPlayerOneAsWinnerFromGame() throws Exception {
        game.scorePointPlayer(1);
        game.scorePointPlayer(1);
        game.scorePointPlayer(1);
        game.scorePointPlayer(1);
        assertThat(game.getWinner(), is(player1));
    }

    @Test
    public void shouldReturnPlayerTwoAsWinnerFromGame() throws Exception {
        game.scorePointPlayer(2);
        game.scorePointPlayer(2);
        game.scorePointPlayer(2);
        game.scorePointPlayer(2);
        assertThat(game.getWinner(), is(player2));
    }

    @Test
    public void shouldPreventWinnerFromBeingWinnerWhenScoringAtDeuce() throws Exception {
        game.scorePointPlayer(1);
        game.scorePointPlayer(1);
        game.scorePointPlayer(1);
        game.scorePointPlayer(2);
        game.scorePointPlayer(2);
        game.scorePointPlayer(2);
        game.scorePointPlayer(1);
        assertNull(game.getWinner());
    }

    @Test
    public void shouldPrintPlayerOneWithAdvantage() throws Exception {
        game.scorePointPlayer(1);
        game.scorePointPlayer(1);
        game.scorePointPlayer(1);
        game.scorePointPlayer(2);
        game.scorePointPlayer(2);
        game.scorePointPlayer(2);
        game.scorePointPlayer(1);



    }
}
